package com.oocl.chatroom.servermanage.view;

import java.util.List;
import org.jdom.Element;
import com.oocl.pojo.Users;


public class HtmlProducer {
	
	public static Element createA(String text, String uri){
		Element a = new Element("a");
		a.setAttribute("href", uri);
		a.setText(text);
		return a;
	}
	
	public static Element createGetButton(String name,String uri){
		Element button = new Element("button");
		Element a = new Element("a");
		a.setAttribute("href", uri);
		button.setText(name);
		button.addContent(a);
		return button;
	}
	
	public static Element creatIndexPage(){
		Element body = new Element("body");
		Element button = new Element("button");
		Element a1 = new Element("a");
		a1.setAttribute("href", "http://localhost:9000/1");
		a1.setText("Start Server");
		button.addContent(a1);
		Element button1 = new Element("button");
		Element a2 = new Element("a");
		a2.setAttribute("href", "http://localhost:9000/2");
		a2.setText("Stop Server");
		button1.addContent(a2);
		Element button2 = new Element("button");
		Element a3 = new Element("a");
		a3.setAttribute("href", "http://localhost:9000/3");
		a3.setText("UserList");
		button2.addContent(a3);
		Element button3 = new Element("button");
		Element a4 = new Element("a");
		a4.setAttribute("href", "http://localhost:9000/4");
		a4.setText("Server run time");
		button3.addContent(a4);
		body.addContent(button);
		body.addContent(button1);
		body.addContent(button2);
		body.addContent(button3);
		return body;
	}
	
	public static Element createListPage(String[] users){
		Element div = new Element("div");
		if(users.length>0){
			div.setAttribute("style", "width:500px; height:300px; overflow:scroll;");
			Element ul = new Element("ul");
			Element li0 = new Element("li");
			ul.addContent(li0);
			li0.setText("online:");
			Element ul1 = new Element("ul");
			Element li1 = new Element("li");
			li1.setText("downline:");
			ul1.addContent(li1);
			for(String name : users){
				String[] strs = name.split(":");
				Element li = new Element("li");
				li.setText(strs[0]);
				if(strs[1].equals("1")){
					ul.addContent(li);
				}else{
					ul1.addContent(li);
				}
			}
			div.addContent(ul);
			div.addContent(ul1);
			
		}
		return div;
	}
	
}
